package com.pine.web.pineframework.controller;

import com.pine.common.beans.ResultVo;
import com.pine.common.beans.pineframework.request.SysDictItemQueryRequest;
import com.pine.common.beans.pineframework.request.SysDictItemSaveOrUpdateRequest;
import com.pine.common.beans.pineframework.response.SysDictItemQueryResponse;
import com.pine.common.beans.request.BatchIdRequest;
import com.pine.common.beans.request.IdRequest;
import com.pine.common.beans.request.PageRequest;
import com.pine.common.beans.response.DeleteResponse;
import com.pine.common.beans.response.PageResponse;
import com.pine.common.systemlog.annotation.SysLog;
import com.pine.manager.pineframework.trigger.SysDictItemTriggerManager;
import com.pine.service.pineframework.SysDictItemService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 系统字典项表 前端控制器
 * </p>
 *
 * @author pine manage
 * @since 2024-08-12
 */
@Tag(name = "系统字典项表前端控制器")
@RestController
@RequestMapping("/sys/dictItem")
public class SysDictItemController {

    @Resource
    private SysDictItemService sysDictItemService;

    /**
     * 分页查询
     *
     * @param request 请求
     * @return 分页响应
     */
    @Operation(summary = "分页查询")
    @PostMapping("/pages")
    @SysLog("分页查询")
    public ResultVo<PageResponse<SysDictItemQueryResponse>> listPages(@RequestBody @Valid PageRequest<SysDictItemQueryRequest> request) {
        request.defaultPage();
        return ResultVo.success(sysDictItemService.listPages(request));
    }

    /**
     * 查询详细信息
     *
     * @param request 请求
     * @return 响应
     */
    @PostMapping(value = "/detail")
    @Operation(summary = "查询详细信息")
    @SysLog("查询详细信息")
    public ResultVo<SysDictItemQueryResponse> getDetail(@RequestBody @Valid IdRequest<Long> request) {
        return ResultVo.success(sysDictItemService.getOneByUniqueKey(request.getId(), "id"));
    }

    /**
     * 新增
     *
     * @param request 请求
     * @return 响应
     */
    @PostMapping(value = "/save")
    @Operation(summary = "新增字典项")
    @SysLog("新增字典项")
    public ResultVo<Boolean> save(@RequestBody @Valid SysDictItemSaveOrUpdateRequest request) {
        Boolean triggerResult = SysDictItemTriggerManager.saveOrUpdate(request);
        return ResultVo.success(triggerResult);
    }

    /**
     * 更新
     *
     * @param request 请求
     * @return 响应
     */
    @PostMapping(value = "/update")
    @Operation(summary = "更新字典项")
    @SysLog("更新字典项")
    public ResultVo<Boolean> update(@RequestBody @Valid SysDictItemSaveOrUpdateRequest request) {
        Boolean triggerResult = SysDictItemTriggerManager.saveOrUpdate(request);
        return ResultVo.success(triggerResult);
    }

    /**
     * 删除
     *
     * @param request 请求
     * @return 响应
     */
    @PostMapping(value = "/delete")
    @Operation(summary = "删除字典项")
    @SysLog("删除字典项")
    public ResultVo<DeleteResponse> delete(@RequestBody @Valid BatchIdRequest<Long> request) {
        DeleteResponse triggerResult = SysDictItemTriggerManager.delete(request);
        return ResultVo.success(triggerResult);
    }
}
